import axios from '@/api/interceptor';
import qs from 'query-string';
import { TimeLineRecord, TimeLineQuery } from './types';

export const selectPageTimeLine = async (params: TimeLineQuery) => {
  const result = await axios({
    url: '/timeline/listPage',
    method: 'GET',
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
  return result.data;
};

export const createTimeLine = async (data: TimeLineRecord) => {
  const result = await axios({
    url: '/timeline/createTimeLine',
    method: 'POST',
    data,
  });
  return result.data;
};

export const removeTimeLine = async (ids: number[]) => {
  const result = await axios({
    url: '/timeline/removeTimeLine',
    method: 'DELETE',
    data: ids,
  });
  return result.data;
};

export const getTimeLineDetail = async (id: number) => {
  const result = await axios({
    url: '/timeline/getTimeLineDetail',
    method: 'GET',
    params: { id },
  });
  return result.data;
};

export const editTimeLine = async (data: TimeLineRecord) => {
  const result = await axios({
    url: '/timeline/editTimeLine',
    method: 'PUT',
    data,
  });
  return result.data;
};
